<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/8/9
  Time: 1:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">

</head>
<body>

<div class="materialContainer">
    <div class="box">
        <div class="title">登录</div>
        <div class="input">
            <label for="name">用户名</label>
            <input type="text" name="name" id="name">
            <span class="spin"></span>
        </div>
        <div class="input">
            <label for="pass">密码</label>
            <input type="password" name="pass" id="pass">
            <span class="spin"></span>
        </div>
        <div class="button login" id="login">
            <button>
                <span>登录</span>
                <i class="fa fa-check"></i>
            </button>
        </div>
        <a href="javascript:" class="pass-forgot">忘记密码？</a>
    </div>

    <div class="overbox">
        <div class="material-button alt-2">
            <span class="shape"></span>
        </div>
        <div class="title">注册</div>
        <div class="input">
            <label for="regname">用户名</label>
            <input type="text" name="regname" id="regname">
            <span class="spin"></span>
        </div>
        <div class="input">
            <label for="regpass">密码</label>
            <input type="password" name="regpass" id="regpass">
            <span class="spin"></span>
        </div>
        <div class="input">
            <label for="reregpass">确认密码</label>
            <input type="password" name="reregpass" id="reregpass">
            <span class="spin"></span>
        </div>
        <div class="button" id="rebutton">
            <button id="regedit">
                <span>注册</span>
            </button>
        </div>
    </div>

</div>

<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/index.js"></script>
<script>

    function print99(x){
        while(x.length>0 && x.charAt(0)==' ')
            x = x.substring(1,x.length);
        while(x.length>0&&x.charAt(x.length-1)==' ')
            x = x.substring(0,x.length-1);
        return x;
    }

    function isNull(elem,message) {
        var va = print99(elem.value);
        if (va == "") {
            alert(message);
            elem.focus();
            return false;
        }
        return true;
    }
    function checkLogin_pw(){
        if(isNull(document.getElementById("pass"),"密码不能为空，请输入密码！")){
            if(document.getElementById("pass").value.length<8){
                alert("密码必须大于等于8位！");
                document.getElementById("pass").value="";
                document.getElementById("pass").focus();
                return false;
            }
        }
        else{
            return false;
        }
    }

    function checkLogin_Name(){
        var first=document.getElementById("name").value.charAt(0);
        var exp=/^[a-zA-Z0-9]+$/;
        if(isNull(document.getElementById("name"),"账号不能为空，请输入账号！")){
            if(first>='a'&&first<='z'||first>='A'&&first<='Z'){
            }
            else{
                alert("登录账号要求以字母开头，请您重新输入！");
                document.getElementById("name").value="";
                document.getElementById("name").focus();
                return false;
            }
            if(!exp.test(document.getElementById("name").value)){
                alert("账号必须是字母或数字！");
                document.getElementById("name").value="";
                document.getElementById("name").focus();
                return false;
            }
            return true;
        }else
        {
            return false;
        }
    }

    document.getElementById("login").onclick=function () {
        if(checkLogin_Name()&&checkLogin_pw())
            return true;
        return false;
    }

    function checkReg_pw(){
        var exp=/^[A-Za-z0-9]+$/;
        if(isNull(document.getElementById("regpass"),"密码不能为空，请输入密码！")){
            if(document.getElementById("regpass").value.length<8){
                alert("密码必须大于等于8位！");
                document.getElementById("regpass").focus();
                return false;
            }

        }
        else{
            return false;
        }
        if(document.getElementById("regpass").value!==document.getElementById("reregpass").value){
            alert("两次密码输入不同!");
            document.getElementById("regpass").focus();
            return false;
        }
        return true;
    }

    function checkReg_Name(){
        var first=document.getElementById("regname").value.charAt(0);
        var exp=/^[a-zA-Z0-9]+$/;
        if(isNull(document.getElementById("regname"),"账号不能为空，请输入账号！")){
            if(first>='a'&&first<='z'||first>='A'&&first<='Z'){
            }
            else{
                alert("登录账号要求以字母开头，请您重新输入！");
                document.getElementById("regname").focus();
                return false;
            }
            if(!exp.test(document.getElementById("regname").value)){
                alert("账号必须是字母或数字！");
                document.getElementById("regname").focus();
                return false;
            }
            return true;
        }else
        {
            return false;
        }
    }
    document.getElementById("rebutton").onclick=function () {

        if(checkReg_Name()&&checkReg_pw()){
            // var Reg_user={
            //     "user_name":document.getElementById("regname").value,
            //     "user_pwd":document.getElementById("regpass").value
            // };
            var user_name=document.getElementById("regname").value;
            var user_pwd=document.getElementById("regpass").value;
            var xmlhttp;
            if (window.XMLHttpRequest)
            {
                //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                xmlhttp=new XMLHttpRequest();
            }
            else
            {
                // IE6, IE5 浏览器执行代码
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.open("POST","${pageContext.request.contextPath}/regedit?user_name="+user_name+"&user_pwd="+user_pwd,true);
            xmlhttp.send();
            return true;
        }
        return false;
    }


</script>
</body>
</html>